#include "GameofLife.h"
#include <cstdlib>
#include <iostream>
#include<stdlib.h>
#include<fstream>
#include<time.h>

using namespace std;

void wait ( int seconds ){
     clock_t endwait;
     endwait = clock () + seconds * CLK_TCK ;
     while (clock() < endwait) {}
     }

void  instruc()
{
	puts("\n\nPRESS Ctrl+C to stop the game.\n");
}

int main(int argc, char *argv[])
{
    FILE * pFile;	//create a file pointer;
    GameofLife* GoL;
	int Col,Row;
    pFile = fopen ("init.txt","r");
	if(pFile == NULL){
             cout<<"Unable to open init.txt";
             throw "invalid file handle";
             }
    
    fscanf ( pFile,"%d,%d",&Row,&Col );
    if(Row >= 2 && Col >= 2) 
           GoL = new GameofLife( Row, Col);
    
    
    int iLit, jLit;
    while(fscanf( pFile, "%d,%d",&iLit,&jLit) != EOF){
                  GoL->lightCell(iLit, jLit);
                  }
    fclose(pFile);
    while(1){
       system("cls");
       GoL->draw();
       GoL->evolve( );
       wait(1);
    }
}
